﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CachingProject
{
    public class Block
    {
        int[] addresses;
        int accessed;
        int size;

        //addy = address, size = block size, W = what word to load addy to
        public Block(int addy, int size, int W)
        {
            addresses = new int[size]; //create the address array
            accessed = 0; //initialize accessed to 0
            this.size = size; //set size
            Load(addy, W); //load the word
        }

        public bool Search(int addy, int W) //addy = address, W = word to check
        {
            return (addresses[W] == addy); //check the word where address would be located
        }
        public void Load(int addy, int W)//addy = address, W = word to load address to
        {
            int temp;
            temp = addy - W; //set temp to address that goes at the beginning of the block
            for (int i = 0; i < size; i++) //iterate through the address array
            {
                addresses[i] = temp; //insert address
                temp++;//increment address to load in next slot
            }
        }
        public int Accessed //getter/setter for accessed variable
        {
            get
            {
                return accessed;
            }
            set
            {
                accessed = accessed + value; //increment will read Accessed = 1; increments accessed
            }
        }
        public void ResetAccess() //used on a hit to reset accessed to 0
        {
            accessed = 0;
        }
//-----------------------------------------------------------------------------
    }
}